package com.ruoyi.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.RegisterDetailedOrder;
import com.ruoyi.domain.RegisterSummaryOrder;
import com.ruoyi.mapper.OrderRegisterMapper;
import com.ruoyi.service.OrderRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 订单登记表
 */
@RestController
@RequestMapping("/hotel/order/register")
public class OrderRegisterController extends BaseController {

    @Autowired
    OrderRegisterService orderRegisterService;

    @Autowired
    OrderRegisterMapper orderRegisterMapper;

    /**
     * 查询订单登记表数据-用
     *
     * @param map
     * @return
     */
    @GetMapping("/getReserveRegisterList")
    public AjaxResult getReserveRegisterList(@RequestParam Map map) {
        Map map1 = orderRegisterService.getReserveRegisterList(map);
        map1.put("reserveRegisterList",(TableDataInfo) map1.get("reserveRegisterList"));
        return success(map1);
    }

    /**
     * 支付校验-用
     *
     * @param jsonArray
     * @return
     */
    @PostMapping("/postPaymentValid")
    public AjaxResult postPaymentValid(@RequestBody JSONArray jsonArray) {
        return orderRegisterService.postPaymentValid(jsonArray);
    }


    /**
     * 添加支付记录-用
     *
     * @param map
     * @return
     */
    @PostMapping("/postPaymentInfo")
    public AjaxResult postPaymentInfo(@RequestBody Map map) {
        return orderRegisterService.postPaymentInfo(map);
    }

    /**
     * 登记表编辑-用
     *
     * @param map
     * @return
     */
    @PostMapping("/postEditPaymentInfo")
    public AjaxResult postEditPaymentInfo(@RequestBody Map map) {
        return toAjax(orderRegisterService.postEditPaymentInfo(map));
    }

    /**
     * 查询登记表订单的支付信息-用
     *
     * @param map
     * @return
     */
    @GetMapping("/getOrderRegisterPayment")
    public AjaxResult getOrderRegisterPayment(@RequestParam Map map) {
        return success(orderRegisterService.getOrderRegisterPayment(map));
    }

    /**
     * 添加返款记录-用
     *
     * @param map
     * @return
     */
    @PostMapping("/postRefundInfo")
    public AjaxResult postRefundInfo(@RequestBody Map map) {
        return orderRegisterService.postRefundInfo(map);
    }

    /**
     * 查询登记表订单的返款信息-用
     *
     * @param map
     * @return
     */
    @GetMapping("/getOrderRegisterRefund")
    public AjaxResult getOrderRegisterRefund(@RequestParam Map map) {
        return success(orderRegisterService.getOrderRegisterRefund(map));
    }

    /**
     * 查询酒店待返款金额
     *
     * @param map
     * @return
     */
    @GetMapping("/getHotelDfkPrice")
    public AjaxResult getHotelDfkPrice(@RequestParam Map map) {
        return success(orderRegisterService.getHotelDfkPrice(map));
    }

    /**
     * 根据批次ID获取这个批次所包含的订单及支付信息
     *
     * @param map
     * @return
     */
    @GetMapping("/getRegisterAndPaymentByBatchId")
    public AjaxResult getRegisterAndPaymentByBatchId(@RequestParam Map map) {
        return success(orderRegisterService.getRegisterAndPaymentByBatchId(map));
    }

    /**
     * 爬虫导入宝尚订单数据
     *
     * @param username
     * @param password
     * @param body
     * @return
     */
    @PostMapping("/importBaoShangOrder")
    public AjaxResult importBaoShangOrder(@RequestHeader(required = false) String username, @RequestHeader(required = false) String password, @RequestBody JSONObject body) {
        return orderRegisterService.importBaoShangOrder(username, password, body);
    }

    /**
     * 根据登记表ID获取登记表数据信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getReserveRegisterById")
    public AjaxResult getReserveRegisterById(@RequestParam String id) {
        return success(orderRegisterService.getReserveRegisterById(id));
    }

    /**
     * 宝尚订单录入
     *
     * @param jsonObject
     * @return
     */
    @PostMapping("/postAddRegister")
    public AjaxResult postAddRegister(@RequestBody JSONObject jsonObject) {
        return orderRegisterService.postAddRegister(jsonObject);
    }

    /**
     * 复制登记表订单
     *
     * @param jsonObject
     * @return
     */
    @PostMapping("/postCopyRegister")
    public AjaxResult postCopyRegister(@RequestBody JSONObject jsonObject) {
        return toAjax(orderRegisterService.postCopyRegister(jsonObject));
    }


    /**
     * 删除登记表订单
     *
     * @param jsonObject
     * @return
     */
    @PostMapping("/postDeleteRegister")
    public AjaxResult postDeleteRegister(@RequestBody JSONObject jsonObject) {
        return orderRegisterService.postDeleteRegister(jsonObject);
    }

    /**
     * 清空登记表订单
     *
     * @param jsonObject
     * @return
     */
    @PostMapping("/postEmptyRegister")
    public AjaxResult postEmptyRegister(@RequestBody JSONObject jsonObject) {
        return orderRegisterService.postEmptyRegister(jsonObject);
    }

    /**
     * 悦游手动导入登记表
     *
     * @param jsonObject
     * @return
     */
    @PostMapping("/postImportRegister")
    public AjaxResult postImportRegister(@RequestBody JSONObject jsonObject) {
        return toAjax(orderRegisterService.postImportRegister(jsonObject));
    }

    /**
     * 导出明细订单excel
     *
     * @param response
     * @param map
     */
    @PostMapping("/handleDetailedExport")
    public void handleDetailedExport(HttpServletResponse response, @RequestParam Map map) {
        List<RegisterDetailedOrder> list = orderRegisterService.getDetailedExport(map);
        ExcelUtil<RegisterDetailedOrder> util = new ExcelUtil<RegisterDetailedOrder>(RegisterDetailedOrder.class);
        util.exportExcel(response, list, "登记表明细数据");
    }

    /**
     * 导出汇总订单excel
     *
     * @param response
     * @param map
     */
    @PostMapping("/handleSummaryExport")
    public void handleSummaryExport(HttpServletResponse response, @RequestParam Map map) {
        List<RegisterSummaryOrder> list = orderRegisterService.getSummaryExport(map);
        ExcelUtil<RegisterSummaryOrder> util = new ExcelUtil<RegisterSummaryOrder>(RegisterSummaryOrder.class);
        util.exportExcel(response, list, "登记表汇总数据");
    }

    @GetMapping("/getYesterdayPaymentPendingCount")
    public AjaxResult getYesterdayPaymentPendingCount(){
        return success();
    }
}